var layerId;
var  clickState = true;
$(function(){
	$("#save-button").click(function(){
		var accountName = $("input[name='accountName']").val();
		var password = $("input[name='password']").val();
		var realName = $("input[name='realName']").val();
		var phone = $("input[name='phone']").val();
		var email = $("input[name='email']").val();
		var isEnabled = $("input[name='isEnabled']:checked").val();
	
		var roles = $(".role-checkbox:checked");
		var adminId = init.adminId;
		var roleIds="";
		if(roles.length>0){
			for(i=0;i<roles.length;i++){
				var roleId = $(roles[i]).attr("data-id");
				roleIds+=roleId+",";
			}
		}
		if(accountName.length==0){
			layer.msg("登录账号不能为空");
			return false;
		}
		if(isEnabled.length==0){
			layer.msg("状态不能为空");
			return false;
		}
		if(adminId.length==0 && password.length==0){
			layer.msg("登录密码不能为空");
			return false;
		}
		
		var adminData ={
			"id":adminId,
			"accountName":accountName,
			"realName":realName,
			"phone":phone,
			"email":email,
			"isEnabled":isEnabled,
			"roleIds":roleIds
		}
		if(password.length>0){
			password =md5(password).toUpperCase();
			adminData.password=password;
		}
		if(clickState){
			clickState = false;
			$.ajax({
				url:basePath+"/admin/save.shtml",
				data:adminData,
				type:"post",
				dataType:"JSON",
				success:ajaxSuccessCloseFun
			});
		}
	});
	$("#close-button").click(function(){
		parent.closeLayer(0);
	});
	
});
